<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"   %>
     
<%@ page import="com.zhouchao.bean.Admin" %>
<%@ page import="com.zhouchao.bean.DormManager" %>
<%@ page import="com.zhouchao.bean.Student"%>
<%@ page import="com.zhouchao.util.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<%
	if(request.getAttribute("user")==null){
		String userName=null;
		String password=null;
		String userType=null;
		String remember=null;
		
		Cookie[] cookies=request.getCookies();
		for(int i=0;cookies!=null && i<cookies.length;i++){
			if(cookies[i].getName().equals("dormuser")){
				userName=cookies[i].getValue().split("-")[0];
				password=cookies[i].getValue().split("-")[1];
				userType=cookies[i].getValue().split("-")[2];
				remember=cookies[i].getValue().split("-")[3];
			}
		}
		
		if(userName==null){
			userName="";
		}
		
		if(password==null){
			password="";
		}
		
		if(userType==null){
			userType="";
		} else if("admin".equals(userType)){
			pageContext.setAttribute("user", new Admin(userName,password));
			pageContext.setAttribute("userType", 1);
		} else if("dormManager".equals(userType)) {
			pageContext.setAttribute("user", new DormManager(userName,password));
			pageContext.setAttribute("userType", 2);
		} else if("student".equals(userType)) {
			pageContext.setAttribute("user", new Student(userName,password));
			pageContext.setAttribute("userType", 3);
		}
		
		if("yes".equals(remember)) {
			pageContext.setAttribute("remember", 1);
		}
		
	}
%>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>安徽中医药大学宿舍管理系统</title>
	<script type="text/javascript" src="bootstrap/js/jQuery.js"></script>  
<script type="text/javascript">
	function changeImg(){  
  var imgSrc = $("#img");  
 
    var src = imgSrc.attr("src");  
    imgSrc.attr("src",chgUrl(src));  
}  



//时间戳  
//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳  
function chgUrl(url){  
    var timestamp = (new Date()).valueOf();  
    url = url.substring(0,17);  
    if((url.indexOf("&")>=0)){  
        url = url + "×tamp=" + timestamp;  
    }else{  
        url = url + "?timestamp=" + timestamp;  
    }  
    return url;  
}  
	
	
	////////////jquery验证阻止表单提交///////////////////
$(document).ready(function(){  
    $(":submit[id=tijiao]").click(function(check){  
        var val = $(":text[id=code]").val();  
      var userName = document.getElementById("userName").value;
		var password = document.getElementById("password").value;
		var userType = document.getElementById("userType").value;
		var code = document.getElementById("code").value;
		var remember=document.getElementById("remember").value;
    
        
		if (userType =="tip") {
			// alert("文本框输入为空，不能提交表单！");  
            $(":text[id=userType]").focus();  
            check.preventDefault();//此处阻止提交表单  
            return false;
		}
		if (userName == null || userName == "") {
			document.getElementById("error").innerHTML = "用户名不能为空";
			// alert("文本框输入为空，不能提交表单！");  
            $(":text[id=userName]").focus();  
            check.preventDefault();//此处阻止提交表单  
              return false;
		}
		if (password == null || password == "") {
			document.getElementById("error").innerHTML = "密码不能为空";
			 //alert("文本框输入为空，不能提交表单！");  
            $(":text[id=password]").focus();  
            check.preventDefault();//此处阻止提交表单  
              return false;
		}
		
		if (code == null || code == "") {
			document.getElementById("error").innerHTML = "验证码不能为空";
			document.getElementByIdx_x("code").focus; 
			 //alert("文本框输入为空，不能提交表单！");  
            $(":text[id=code]").focus();  
            check.preventDefault();//此处阻止提交表单  
              return false;
		}
        
        
        
    });  
});  


//////////////////////////////
	
	
	
	
	
	
	
	
	function checkForm() {
		var userName = document.getElementById("userName").value;
		var password = document.getElementById("password").value;
		var userType = document.getElementById("userType").value;
		var code = document.getElementById("code").value;
		var remember=document.getElementById("remember").value;
		
		if (userType =="tip") {
			document.getElementById("error").innerHTML = "请选择用户类型";
			return false;
		}
		if (userName == null || userName == "") {
			document.getElementById("error").innerHTML = "用户名不能为空";
			
			return false;
		}
		if (password == null || password == "") {
			document.getElementById("error").innerHTML = "密码不能为空";
			return false;
		}
		
		if (code == null || code == "") {
			document.getElementById("error").innerHTML = "验证码不能为空";
			document.getElementByIdx_x("code").focus; 
			return false;
		}
		
		code = "codetemp=" + code;  
  	  $.ajax({  
        type:"POST",  
         url:"codeser", 
        data:code,  
        success:callback
   	 });  
	
	}
	
	
	function callback(data){ 
	
	if(data==2){
	alert("验证码错误");
	//document.getElementById("error").innerHTML = "验证码错误";
	//window.parent.window.location.href="login.jsp";
	//$("#info").html("验证码错误");
		return false;
	}else{
	var userName = document.getElementById("userName").value;
	var password = document.getElementById("password").value;
	var userType = document.getElementById("userType").value;
	var remember=document.getElementById("remember").value;
	//window.parent.window.location.href="login?userType="+userType+"&password="+password+"&userName="+userName+"&remember="+remember;
	//	window.parent.window.location.href="main.jsp";
	//document.myForm.action="login";
	return true;
	}
  
}

function changeval(){
           var check = document.getElementById("remember");
            if(check.checked == true){
                 document.getElementById("remember").value = "remember-me";
            }else{
                 document.getElementById("remember").value = "0";
             }
    }


  
</script>
	
	<style type="text/css">
	
		body {
			margin-left: 0px;
			margin-top: 0px;
			margin-right: 0px;
			margin-bottom: 0px;
		}
		.STYLE5 {
	FONT-FAMILY: "宋体"; COLOR: #ffffff; FONT-SIZE: 14px; FONT-WEIGHT: bold
}
.STYLE9 {
	LINE-HEIGHT: 18px; FONT-FAMILY: "宋体"; COLOR: #333333; FONT-SIZE: 12px
}
.STYLE4 {
	LINE-HEIGHT: 24px; FONT-FAMILY: "宋体"; COLOR: #999999; FONT-SIZE: 13px
}
.STYLE12 {
	LINE-HEIGHT: 24px; COLOR: #999999; FONT-SIZE: 13px
}
.STYLE13 {
	FONT-SIZE: 14px; FONT-WEIGHT: bold
}
.STYLE16 {
	LINE-HEIGHT: 20px; FONT-FAMILY: "宋体"; COLOR: #666666; FONT-SIZE: 12px
}
.botframe_xf {
    border-top: 2px solid #67BDED;
    float: left;
    padding: 10px 0;
    width: 100%;
}
.copy {
	font: 100 12px tahoma,Arial,"宋体";
    color: #404143;
    line-height: 20px;
    text-align: center;
}
.copy a {
    color: #404143 !important;
}
a {
    color: #4D4D4D;
    text-decoration: none;
}
a:hover {
    color: #005197;
    text-decoration: underline;
}
	
	</style>
</head>
<base href="<%=basePath%>">
<body >

<FORM  name="myForm" action="login" class="form-signin"  method="post"> 
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
  <TBODY>
  <TR>
    <TD align=middle>
      <TABLE border=0 cellSpacing=0 cellPadding=0 width=1024>
        <TBODY>
        <TR>
          <TD>
            <TABLE id=__01 border=0 cellSpacing=0 cellPadding=0 width=1024>
              <TBODY>
              <TR>
                <TD><IMG alt="" src="images/ahcm.jpg" width="520" 
                  height="102"></TD>
				<td align="right" colspan="2">  
				  </TR>
              <TR>
                <TD><IMG alt="" src="images/ahh.jpg" width=520 
                  height=343></TD>
                <TD><IMG alt="" src="images/ahh_2.jpg" width=193
                  height=343></TD>
                <TD height=243 background="images/cc.jpg" width=320>
                  <TABLE border=0 cellSpacing=0 cellPadding=0 width="96%">
                    <TBODY>
                    
                    <TR>
                      <TD width="5%">&nbsp;</TD>
                      <TD height=40 align=left><IMG alt="" align=absMiddle 
                        src="images/3_10.jpg" width=48 
                        height=38>&nbsp; <SPAN class=STYLE5>用户登录</SPAN>
                       
                        </TD></TR>
                    <TR>
                      <TD height=110>&nbsp;</TD>
                      <TD>
                        <TABLE border=0 cellSpacing=0 cellPadding=0 width=282 >
                          <TBODY>
                          
                          <TR>
                            <TD class=STYLE9 height=35 width=57 
                              align=right>角&nbsp;&nbsp;色：</TD>
                            <TD colSpan=2 align=left>
								<select name ="userType" id="userType" class="input7"  title="请选择角色" ">
          							 <option selected="selected" value="tip">请选择角色</option>
          							  <option value="admin"${userType==1?'selected':''} >系统管理员</option>
          							   <option value="dormManager"${userType==2?'selected':''}>宿舍管理员</option>
          							    <option value="student"${userType==3?'selected':''}>学生</option>
        						</select>
							</TD>
							<TD class=STYLE9 height=35 width=77 align=right>&nbsp;&nbsp;</TD>
							</TR>
                          <TR>
                            <TD class=STYLE9 height=35 width=57 
                              align=right>用户名：</TD>
                            <TD colSpan=2 align=left>
								<input type="text" id="userName" name="userName" value="${user.userName }">
							</TD>
								<TD class=STYLE9 height=35 width=77 align=left><input id="remember" name="remember" value="0" type="checkbox" ${remember==1?'checked':''} onchange="changeval()">记住我 </TD>
							
							</TR>
                          <TR>
                            <TD class=STYLE9 height=35 
                              align=right>密&nbsp;&nbsp;码：</TD>
                            <TD colSpan=2 align=left>
                            <input type="password" id="password" name="password" value="${user.password }"></TD></TR>
                         <TR>
                            <TD class=STYLE9 height=35 width=57 align=right>验证码：</TD>
                            <TD colSpan=2 align="left">
                               <input  id="code" type="text"  style="width:66px;">
                               <span  >   <img id="img" alt="" src="http://localhost:8080/dorm/code" class=STYLE9 height=22 width=66 /> </span>
                            </TD>
                            	<TD class=STYLE9 height=35 width=77 align=left><a href="#" onclick="changeImg()">换一个</a></TD>
                            </TR>
                            
                               <TR>
                            <TD></TD>
                              <TD class=STYLE9 height=25 width=77 align=left><font id="error" color="red">${error }</font> </TD>
                            <TD >
                             
                            </TD>
                            	
                            </TR>
                            
                            
                    <TR>
                      <TD></TD>
                      <TD height=10>
                     &nbsp;<input type="submit"  id="tijiao" onclick="checkForm()" value="登录"/>&nbsp;&nbsp;&nbsp;<input type="reset" value="重置"/>
                      </TD></TR></TBODY></TABLE></TD></TR></TABLE>
              <TR>
                <TD height=198 colSpan=3>
                  <TABLE border=0 cellSpacing=0 cellPadding=0 width=1024>
                    <TBODY>
                    <TR>
                      <TD width=52>&nbsp;</TD>
                      <TD width=920>
                        <TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
                          <TBODY>
                          <TR>
                            <TD>&nbsp;</TD></TR>
                          <TR>
                            <TD align=middle><FONT color=red></FONT></TD></TR>
                          <TR>
                            <TD align=left>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN 
                              class=STYLE13>登录说明：</SPAN></TD></TR>
                          <TR>
                            <TD 
                          background=/epstar/login/images/ccnu/a_06.jpg>&nbsp;</TD></TR>
           <!--       <tr>
                    <td align="left">&nbsp;&nbsp;<span class="STYLE16">&nbsp;宿舍预约登录方式：研究生新生登录用户名为<b>学号</b>，密码为<b>身份证后六位</b>，末位为X的默认为小写x，若密码不对请尝试用“888888”(6个8)。
					</span></td>
                  </tr>
                  <tr>
                    <td align="left">&nbsp;&nbsp;<span class="STYLE16">&nbsp;参加宿舍预约对象：2013级研究生新生。</span><span style="color:red;font-size:12px;">免费师范生不参加网上住宿预约和网上选房，由学校安排住宿。</span></td>
                  </tr>
                  <tr>
                    <td align="left">&nbsp;&nbsp;<span class="STYLE16">&nbsp;宿舍预约开通时段：请研究生新生于<b>6月25日8：00至6月30日18:00</b>登录系统申请预约宿舍。</span><span style="color:red;font-size:12px;"><b>预约申请截止时间延长至7月7日18:00。</b></span></td>
                  </tr>				  
                  <tr>
                    <td align="left">&nbsp;&nbsp;<span class="STYLE16">&nbsp;咨询电话：027-67867049&nbsp;&nbsp;027-67861491&nbsp;&nbsp;027-67861000</span></td>
                  </tr>
                  <tr>
                    <td align="left">&nbsp;&nbsp;<span style="color:red;font-size:12px;">&nbsp;注：无论是否选择在校住宿都请登录系统进行申请。如无须在校住宿，请登录系统申请“不住”。规定时段内未预约申请，系统将不预留房间且不安排住宿。</span></td>
                  </tr>		 -->			  
              						
						<TR>
                            <TD 
                              align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              <SPAN class=STYLE16>&gt; 
                              研究生新生登录用户名为<b>学号</b>，密码为<b>身份证号最后六位（末位X请用大写）</b>，如果密码不对请尝试用“888888”(6个8)</SPAN></TD></TR>
                          <TR>
                            <TD 
                              align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              <SPAN class=STYLE16>&nbsp; 
                              在校学生可以通过学校信息门户进入宿舍系统。登录学校信息门户后，选择“后勤服务”菜单，点击“宿舍信息”进入系统。</SPAN></TD></TR>
						  <TR>
                            <TD 
                              align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              <SPAN class=STYLE16 style="color:red;font-size:12px;">&nbsp; 
                             注：您的住宿信息以系统查询的住宿信息为准，报到时按此入住，9月1日后您可以登录系统查看自己的住宿房间。</SPAN></TD></TR>
                          <TR>							  
						 <TR>
                            <TD 
                              align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              <SPAN class=STYLE16>&nbsp; 
                              咨询电话：宿管中心 0551-22222222  学生工作部 0551-6666666  研究生工作处 0551-88888888</SPAN></TD></TR>
						  <TR>
                            <TD>&nbsp;</TD></TR></TBODY></TABLE></TD>
                      <TD width=52>&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
	  <tr>
		<td  colSpan=3 align=middle>
		<div class="botframe_xf">
				<div class="copy"><span> &copy;1999-2012 <a target="_blank" href="">
				安徽中医药大学</a> 版权所有<br>
				设计开发<a target="_blank" href="#">:周超</a>
				
				&nbsp;|&nbsp;
				推荐使用IE11.0及以上浏览器访问本网站</span>
				
				</div>
		</div>	
		</td>
	  </tr>
        <!--      <TR>
                <TD class=STYLE4 bgColor=#f0f0f0 height=83 colSpan=3 
                align=middle>Copyright © 华中师范大学 2012, All Rights Reserved 
                  <BR>推荐使用IE7.0以上浏览器，1024*768分辨率访问本网站</TD></TR>
				  -->
				  </TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM>
</body>
</html>
